/**
* COPYRIGHT. whx. ALL RIGHTS RESERVED.
* Project: just-core
* Author: whx <harrywu304@gmail.com>
* Create On: Dec 15, 2011 6:21:56 PM
*/

package org.justframework.server;

import java.util.Map;

import org.justframework.core.helper.ConfigHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * server connector factory
 */
public class ServerConnectorFactory {
	
	/**
	 * logger
	 */
	private static Logger logger = LoggerFactory.getLogger(ServerConnectorFactory.class);
	
	/**
	 * schema server connector mapping
	 */
	private static Map<String,String> schemaServerMapping = ConfigHelper.getMap("schema_server_connector_mapping");
	
	/**
	 * get server connector by schema and port
	 * @param schema
	 * @param port
	 * @return
	 */
	public static ServerConnector getServerConnector(String schema, int port){
		ServerConnector connector = null;
		try{
			String serverClass = schemaServerMapping.get(schema);
			Class cntKlass = Class.forName(serverClass);
			connector = (ServerConnector) cntKlass.newInstance();
			connector.setPort(port);
		}catch(Exception e){
			logger.error("create server connector fail!!",e);
		}
		return connector;
	}

}
